From: Carlos Garnacho Date: Fri, 29 Aug 2025 21:36:32 +0000 (+0200) Subject: slider: Add a step() method X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~104^2^2~17 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=459cbe7dc8529178bc104433431343e3872092b5;p=gnome-shell.git slider: Add a step() method This method takes a (possibly fractional) number of scroll steps, and converts it to the right amount to move the slider value. Part-of: --- diff --git a/js/ui/slider.js b/js/ui/slider.js index 3b0a3b7cf..ebd181e37 100644 --- a/js/ui/slider.js +++ b/js/ui/slider.js @@ -148,26 +148,38 @@ export const Slider = GObject.registerClass({ return Clutter.EVENT_PROPAGATE; } + step(nSteps) { + const delta = nSteps * SLIDER_SCROLL_STEP; + const value = Math.min(Math.max(0, this._value + delta), this._maxValue); + + if (value !== this.value) { + this.value = value; + return true; + } + + return false; + } + scroll(event) { let direction = event.get_scroll_direction(); - let delta = 0; + let nSteps = 0; if (event.get_flags() & Clutter.EventFlags.FLAG_POINTER_EMULATED) return Clutter.EVENT_PROPAGATE; if (direction === Clutter.ScrollDirection.DOWN) { - delta = -SLIDER_SCROLL_STEP; + nSteps = -1; } else if (direction === Clutter.ScrollDirection.UP) { - delta = SLIDER_SCROLL_STEP; + nSteps = 1; } else if (direction === Clutter.ScrollDirection.SMOOTH) { let [dx] = event.get_scroll_delta(); - delta = dx * SLIDER_SCROLL_STEP; + nSteps = dx; // Match physical direction if (event.get_scroll_flags() & Clutter.ScrollFlags.INVERTED) - delta *= -1; + nSteps *= -1; } - this.value = Math.min(Math.max(0, this._value + delta), this._maxValue); + this.step(nSteps); return Clutter.EVENT_STOP; }